package com.example.admin.myapplication;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class FragmentChats extends Fragment{
    private List<Imge> imgeList = new ArrayList<>();
    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.chats,container,false);
        initImge();
        ImgeAdapter adapter = new ImgeAdapter(getContext(), R.layout.imge_main, imgeList);
        ListView listView = (ListView) view.findViewById(R.id.list_view_chats);
        listView.setAdapter(adapter);

        listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                Imge imge = imgeList.get(position);
                Intent intent = new Intent(getContext(), ChatActivity.class);
                intent.putExtra("name", imge.getName());
                startActivity(intent);
            }
        });

        return view;
    }
    private void initImge() {
        for (int i = 0; i < 5; i++) {
            imgeList.add(new Imge("Apple", R.drawable.chat));
        }
    }





}